import netron
import torch
import torchvision
from torch.utils.data import DataLoader
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim

from torch.autograd import Variable
import torchvision.transforms as transforms
from torch.utils.data import Dataset
import numpy as np
import cv2

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(3, 10, kernel_size=5)
        self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
        self.conv2_drop = nn.Dropout2d()
        self.fc1 = nn.Linear(1280, 1000)
        self.fc2 = nn.Linear(1000, 50)
        self.fc3 = nn.Linear(50,3)

    def forward(self, x):
        x = F.relu(F.max_pool2d(self.conv1(x), 2))
        x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))
        x = F.avg_pool2d(x, 7)
        x = x.view(x.size(0),-1)
        # print(x.size(1))
        x = F.relu(self.fc1(x))
        x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        x = self.fc3(F.relu(x))
        return x

def test():
    net=Net()
    x=torch.randn(2,3,256,256)
    y=net(x)
    print(y.size())
    print(y)
    onnx_path = "onnx_model_name.onnx"
    torch.onnx.export(net,x, onnx_path)

    # netron.start(onnx_path)

if __name__=="__main__":
    test()
